<?php
namespace common\service;


class RedisServer extends BaseService
{
    public static $redis = null;
    /**
     * 初始化redis
     * @return object
     */
    public static function  initialization()
    {
        self::$redis = new \Redis();
        self::$redis->connect('127.0.0.1',6379);
        return new self();

    }

    /**
     * 设置值
     * @param $key
     * @param $val
     * @return object
     */
    public  static function addRedis($key,$val){
        self::$redis->set($key,$val);
        return new self();
    }

    /**
     * 获取值
     * @param $key
     * @param $default
     * @return bool|string
     */
    public static function getRedis($key = '',$default = ''){
        if($key == '')
        {
            return $default;
        }
        return self::$redis->get($key);
    }

    /**
     * 删除redis
     * @param string $key
     * @return string
     */
    public static function delRedis($key = ''){
        if($key == '')
        {
            return '';
        }
        return self::$redis->del($key);

    }

}